<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>03-路径操作-矩形</title>
  <style>
    body {
      background-color: #000;
      text-align: center;
    }
    #c1 {
      background-color: #fff;
    }
  </style>
</head>
<body>
  <canvas id="c1" width="1000" height="800"></canvas>

  <script>
    window.onload = function() {
      const oC = document.getElementById('c1')
      const gd = oC.getContext('2d')

      gd.beginPath()
      // 绘制矩形
      // 方式1：矩形左上角坐标，矩形宽度，矩形高度
      gd.rect(100, 100, 300, 200)
      // 矩形边框
      gd.strokeStyle = 'green'
      gd.lineWidth = 5
      gd.stroke()

      gd.beginPath()
      gd.rect(100, 400, 300, 200)
      // 矩形填充
      gd.fillStyle = '#f40'
      gd.fill()
    }
  </script>
</body>
</html>